﻿<Window x:Class="SellAvi.Views.WindowAppSettings"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:converters="clr-namespace:SellAvi.Views.Converters"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:command="http://www.galasoft.ch/mvvmlight"
        Title="Настройки программы" Height="300" Width="500"
        DataContext="{Binding AppSettings, Source={StaticResource Locator}}">
    <Window.Resources>
        <converters:RadioButtonConverter x:Key="rbc" />
        <Style TargetType="{x:Type ComboBox}">
            <Setter Property="Margin" Value="0,2,0,2" />
        </Style>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="Margin" Value="0,2,0,2" />
        </Style>
        <Style TargetType="{x:Type CheckBox}">
            <Setter Property="Margin" Value="0,2,0,2" />
        </Style>
    </Window.Resources>
    <DockPanel>
        <DockPanel Dock="Bottom" Height="26">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Margin="2" HorizontalAlignment="Left" MinWidth="80" Content="Настройки по умолчанию" Command="{Binding RestoreUserSettingsCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"/>
                <Button Margin="2" HorizontalAlignment="Right" MinWidth="80" Content="Сохранить" Command="{Binding SaveUserSettingsCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"/>
            </StackPanel>
        </DockPanel>
        <TabControl TabStripPlacement="Left">
            <TabItem Header="Защитный код">
                <Grid Background="#FFE5E5E5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <!--=================================-->
                    <TextBlock Grid.Row="0" Grid.Column="0">           
                        <Hyperlink Command="{Binding NavigateToCommand}" CommandParameter="https://rucaptcha.com/?from=1730798">
                            <Hyperlink.Inlines>
                                <Run Text="Получить код"/>
                            </Hyperlink.Inlines>
                        </Hyperlink>
                    </TextBlock>
                    <Label Grid.Row="1" Grid.Column="0" Content="Сервис:"/>
                    <Label Grid.Row="2" Grid.Column="0" Content="Captcha KEY:"/>
                    <Label Grid.Row="3" Grid.Column="0" Content="Ожидание (с.):" ToolTip="Время, даваемое сервису ruCaptcha на разгадывание защитного кода."/>
                    <Label Grid.Row="4" Grid.Column="0" Content="Кол. попыток:" ToolTip="Количество попыток ввода защитного кода при автоматическом распознавании."/>


                    <CheckBox Grid.Row="0" Grid.Column="1" Content="Использовать автоматическое распознавание" IsChecked="{Binding CaptchaIsAutomatic}" Name="CheckIsAutomatic"/>
                    <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding CaptchaToken}" IsEnabled="{Binding ElementName=CheckIsAutomatic, Path=IsChecked}"/>
                    <TextBox Grid.Column="1" Grid.Row="3" Text="{Binding CaptchaTimeout}"/>
                    <TextBox Grid.Column="1" Grid.Row="4" Text="{Binding CaptchaTrials}"/>
                    <ComboBox Grid.Column="1" Grid.Row="1">
                        <ComboBoxItem IsSelected="True">rucaptcha.com</ComboBoxItem>
                    </ComboBox>
                </Grid>
            </TabItem>
            <TabItem Header="Публикация">
                <Grid Background="#FFE5E5E5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />

                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Label Grid.Row="0" Grid.Column="0" Content="Интервал между публикациями:" ToolTip="При публикации нескольких товаров подряд в автоматическом режиме рекомендуется делать интервал (с.), имитирующий время ручного заполнения формы на сайте."/>
                    <Label Grid.Row="1" Grid.Column="0" Content="Игнорировать ошибки публикации:" ToolTip="При автоматической публикации может возникнуть неразрешимая ситуация, когда товар не может быть размещен из-за необходимости ввода дополнительных параметров товара."/>
                    <Label Grid.Row="2" Grid.Column="0" Content="Общий регион публикации товаров:" ToolTip="Если установлен общий регион, то при размещении товаров будет использован регион личного кабинета из-под которого выполняется публикация."/>

                    <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding PublicationTimeout}"/>
                    <!--НЕ ИСПОЛЬЗОВАТЬ GroupName для RadioButton-->
                    <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
                        <RadioButton Content="да" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=PublicationSkipErrors, Mode=Default}"/>
                        <RadioButton Content="нет" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=PublicationSkipErrors, Converter={StaticResource rbc}}"/>
                    </StackPanel>
                    <StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
                        <RadioButton Content="да" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=PublicationCommonUserRegion, Mode=Default}"/>
                        <RadioButton Content="нет" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=PublicationCommonUserRegion, Converter={StaticResource rbc}}"/>
                    </StackPanel>
                </Grid>
                <!--=================================-->
            </TabItem>
            <TabItem Header="Активация">
                <Grid Background="#FFE5E5E5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />

                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Label Grid.Row="0" Grid.Column="0" Content="Интервал между активациями:" ToolTip="Задержка в секундах между активациями объявлений (рекомендуется использовать задержку не менее 300 секунд)"/>
                    <Label Grid.Row="1" Grid.Column="0" Content="Количество страниц обхода ЛК:" ToolTip="Количество страниц ЛК, обрабатываемое загрузчиком, при нажатии на кнопку 'Загр. неактивированные'"/>

                    <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding ActivationTimeOut}"/>
                    <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding ActivationPagesNum}"/>

                </Grid>
                <!--=================================-->
            </TabItem>
            <TabItem Header="Сборщик">
                <Grid Background="#FFE5E5E5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />

                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Label Grid.Row="0" Grid.Column="0" Content="Задержка при сборе объявлений:"/>
                    <Label Grid.Row="1" Grid.Column="0" Content="Вырезать html теги из описания:"/>
                    <Label Grid.Row="2" Grid.Column="0" Content="Загружать фотографию товара:"/>
                    <Label Grid.Row="3" Grid.Column="0" Content="Загружать телефон владельца:"/>
                    <Label Grid.Row="4" Grid.Column="0" Content="Метод распознавания телефона:"/>
                    <Label Grid.Row="5" Grid.Column="0" Content="Предупреждать об ошибках сбора:"/>
                    <Label Grid.Row="6" Grid.Column="0" Content="Загружать дубликаты объявлений:"/>
                    <Label Grid.Row="7" Grid.Column="0" Content="Цена в объявлении (только число):"/>

                    <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding ParserPolling}"/>
                    <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
                        <RadioButton Content="да" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=ParserTrimHtml, Mode=Default}"/>
                        <RadioButton Content="нет" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=ParserTrimHtml, Converter={StaticResource rbc}}"/>
                    </StackPanel>
                    <StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
                        <RadioButton Content="да" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=ParserDownloadImages, Mode=Default}"/>
                        <RadioButton Content="нет" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=ParserDownloadImages, Converter={StaticResource rbc}}"/>
                    </StackPanel>
                    <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal">
                        <RadioButton Content="да" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=ParserDownloadPhones, Mode=Default}" Name="RbtAllowPhones"/>
                        <RadioButton Content="нет" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding ElementName=RbtAllowPhonesPath, Path=IsChecked, Converter={StaticResource rbc}}"/>
                    </StackPanel>
                    <ComboBox Grid.Row="4" Grid.Column="1" ItemsSource="{Binding ParserPhoneMode}" SelectedIndex="0" x:Name="ParserComboBox" IsEnabled="{Binding ElementName=RbtAllowPhones, Path=IsChecked}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <command:EventToCommand Command="{Binding ParserPhoneModeCommand}" CommandParameter="{Binding ElementName=ParserComboBox, Path=SelectedIndex}">
                                </command:EventToCommand>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </ComboBox>
                    <StackPanel Grid.Row="5" Grid.Column="1" Orientation="Horizontal">
                        <RadioButton Content="да" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=ParserShowErrors, Mode=Default}"/>
                        <RadioButton Content="нет" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=ParserShowErrors, Converter={StaticResource rbc}}"/>
                    </StackPanel>
                    <StackPanel Grid.Row="6" Grid.Column="1" Orientation="Horizontal">
                        <RadioButton Content="да" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=ParserAllowDuplicates, Mode=Default}"/>
                        <RadioButton Content="нет" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=ParserAllowDuplicates, Converter={StaticResource rbc}}"/>
                    </StackPanel>
                    <StackPanel Grid.Row="7" Grid.Column="1" Orientation="Horizontal">
                        <RadioButton Content="да" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=ParserTrimPrice, Mode=Default}"/>
                        <RadioButton Content="нет" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=ParserTrimPrice, Converter={StaticResource rbc}}"/>
                    </StackPanel>
                </Grid>
            </TabItem>
            <TabItem Header="Анонимность">
                <StackPanel Background="#FFE5E5E5">

                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                        <RadioButton x:Name="btnUsingTor" Content="TOR" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=TorInPriority, Mode=Default}"/>
                        <RadioButton x:Name="btnUsingProxy" Content="PROXY" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=TorInPriority, Converter={StaticResource rbc}}"/>
                    </StackPanel>


                    <GroupBox Margin="5,0,5,0" Header="Настройки Tor:" IsEnabled="{Binding ElementName=btnUsingTor, Path=IsChecked}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="120" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <!--<Label Grid.Row="0" Grid.Column="0" Content="сервер:"/>-->

                            <Label Grid.Row="1" Grid.Column="0" Content="выходные узлы:"/>
                            <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding TorExitNodes}"/>
                        </Grid>
                    </GroupBox>


                    <GroupBox Margin="5,0,5,0" Header="Настройки Proxy:" IsEnabled="{Binding ElementName=btnUsingProxy, Path=IsChecked}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />

                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="120" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <Label Grid.Row="0" Grid.Column="0" Content="сервер:порт"/>
                            <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding ProxyServer}"/>
                            <Label Grid.Row="1" Grid.Column="0" Content="логин:"/>
                            <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding ProxyLogin}"/>
                            <Label Grid.Row="2" Grid.Column="0" Content="пароль:"/>
                            <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding ProxyPassword}"/>
                        </Grid>

                    </GroupBox>
                </StackPanel>
            </TabItem>
            <TabItem Header="Прочее">
                <Grid Background="#FFE5E5E5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />

                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Label Grid.Row="0" Grid.Column="0" Content="Настройка UserAgent:"/>
                    <ComboBox x:Name="WebClientAgentCombobox" Grid.Row="0" Grid.Column="1" ItemsSource="{Binding WebClientAgents}" SelectedIndex="0">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <command:EventToCommand Command="{Binding WebClientAgentCommand}" CommandParameter="{Binding ElementName=WebClientAgentCombobox, Path=SelectedIndex}">
                                </command:EventToCommand>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </ComboBox>
                </Grid>
            </TabItem>
        </TabControl>

    </DockPanel>
</Window>
